/**日期时间处理 
 * // 将时间戳转换为可读时间格式
*/
export const formatToTimestamp = (timeStr) => {
  if (!timeStr) return '-'
  
  try {
    // 如果输入的是时间戳（纯数字），则转换为可读格式
    const timestamp = parseInt(timeStr)
    if (!isNaN(timestamp) && timestamp > 0) {
      const date = new Date(timestamp)
      if (isNaN(date.getTime())) return timeStr
      
      const year = date.getFullYear()
      const month = String(date.getMonth() + 1).padStart(2, '0')
      const day = String(date.getDate()).padStart(2, '0')
      const hours = String(date.getHours()).padStart(2, '0')
      const minutes = String(date.getMinutes()).padStart(2, '0')
      const seconds = String(date.getSeconds()).padStart(2, '0')
      
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
    }
    
    // 如果不是时间戳，尝试作为普通时间字符串处理
    const date = new Date(timeStr)
    if (isNaN(date.getTime())) return timeStr
    
    const year = date.getFullYear()
    const month = String(date.getMonth() + 1).padStart(2, '0')
    const day = String(date.getDate()).padStart(2, '0')
    const hours = String(date.getHours()).padStart(2, '0')
    const minutes = String(date.getMinutes()).padStart(2, '0')
    const seconds = String(date.getSeconds()).padStart(2, '0')
    
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  } catch (error) {
    console.error('时间格式化错误:', error)
    return timeStr
  }
}
// 格式化时间
export const formatTime = (timeStr) => {
  if (!timeStr) return '-'
  
  try {
    const date = new Date(timeStr)
    if (isNaN(date.getTime())) return timeStr
    
    const year = date.getFullYear()
    const month = String(date.getMonth() + 1).padStart(2, '0')
    const day = String(date.getDate()).padStart(2, '0')
    const hours = String(date.getHours()).padStart(2, '0')
    const minutes = String(date.getMinutes()).padStart(2, '0')
    const seconds = String(date.getSeconds()).padStart(2, '0')
    
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  } catch (error) {
    console.error('时间格式化错误:', error)
    return timeStr
  }
}